<?php
/**
 * 数据库辅助类，用来载入配置文件，并生成一个IConnector实现类的对象
 * @author lfYang
 *
 */
class DBHelper {
	/**
	 * <h2>返回一个IConnector对象</h2>
	 *
	 * @param boolean $param_queries
	 *        	是否参数化查询，默认true
	 * @param boolean $debug
	 *        	是否开启调试模式，默认false
	 * @return IConnector
	 * @see ../lib/IConnector.php
	 */
	static function getDB($param_queries = true, $debug = false) {
		$cn = 'PdoConnector';
		$db [IConnector::CONN_HOSTNAME] = DB_URL;
		$db [IConnector::CONN_DATABASE] = DB_NAME;
		$db [IConnector::CONN_USERNAME] = DB_USR;
		$db [IConnector::CONN_PASSWORD] = DB_PWD;
		$db [IConnector::CONN_PERSISTENT] = DB_PCONN;
		$db [IConnector::CONN_DRIVER] = DB_PDO_DRIVER;
		$db [IConnector::CHAR_APPLICATION] = GG_APP_CHARSET;
		$db [IConnector::CHAR_DATABASE] = GG_DB_CHARSET;
		$dbOptions [IConnector::LOG_DEBUG] = $debug;
		$dbOptions [IConnector::PARAM_QUERIES] = $param_queries;
		
		$conn = ConnectorFactory::create ( $cn, $db, $dbOptions );
		
		if (! empty ( $conn )) {
			$conn->getLink ()->exec ( "SET NAMES " . GG_MYSQL_CHARSET );
		} else {
			GF::oops ( '<b>Create DB connection failed.</b>' );
		}
		return $conn;
	}
}